package com.excilys.ymca.view;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.excilys.ymca.model.Contact;

/**
 * Adaptateur entre une liste de contacts, et une ListView.
 * 
 * @author Pierre-Yves Ricau
 * 
 */
public class ContactAdapter extends ArrayAdapter<Contact> {

	public ContactAdapter(Context context, List<Contact> contacts) {
		super(context, android.R.layout.two_line_list_item, contacts);
	}

	@Override
	public View getView(int position, View listItem, ViewGroup parent) {

		if (listItem == null) {
			listItem = View.inflate(getContext(), android.R.layout.two_line_list_item, null);
		}
		Contact contact = getItem(position);

		TextView text1 = (TextView) listItem.findViewById(android.R.id.text1);
		TextView text2 = (TextView) listItem.findViewById(android.R.id.text2);

		text1.setText(contact.getName());
		text2.setText(contact.getPhoneNumber());

		return listItem;
	}

}
